﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="paringliht_v5_kehtetudnimed", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(ParinglihtV5Kehtetudnimed))]
    public class ParinglihtV5KehtetudnimedSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IParinglihtV5Kehtetudnimed clazz;
        
        public ParinglihtV5KehtetudnimedSerializer(IParinglihtV5Kehtetudnimed clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            for (int x = 0; ((clazz.Evnimi != null) 
                        && (x < clazz.Evnimi.Count)); x = (x + 1)) {
                if (clazz.Evnimi[x]!=null) {
                    Writer.WriteStartElement("evnimi");
                    global::Xtee.Core.SerializationMetadata metaEvnimi = this.GetMetaData(clazz.Evnimi[x]);
                    Writer.WriteTypeAttribute(metaEvnimi.TypeQualifiedName.Namespace, metaEvnimi.TypeQualifiedName.Name);
                    metaEvnimi.NewSerializer(clazz.Evnimi[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="evnimi") {
                clazz.Evnimi = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtV5Kehtetunimi>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "evnimi")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringliht_v5_kehtetudnimed>evnimi");
                    }
                    global::Xtee.Core.SerializationMetadata metaEvnimi = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtV5Kehtetunimi>(Reader, "paringliht_v5_kehtetunimi", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                    global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtV5Kehtetunimi item = metaEvnimi.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtV5Kehtetunimi>();
                    clazz.Evnimi.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("evnimi");
                        metaEvnimi.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
            }
        }
    }
}
